import history from 'libs/history';

export function jump(path=null) {
    if (path){
        history.push(path)
    }else {
        if (history.location.state && history.location.state['from']) {
            history.push(history.location.state['from']);
        } else {
            history.push('/welcome/index')
        }
    }
}

export function urlEncode(param, key, encode) {
    if(param==null) return '';
    var paramStr = '';
    var t = typeof (param);
    if (t === 'string' || t === 'number' || t === 'boolean') {
        paramStr += '&' + key + '=' + ((encode==null||encode) ? encodeURIComponent(param) : param);
    } else {
        for (let i in param) {
            var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i);
            paramStr += urlEncode(param[i], k, encode);
        }
    }
    return paramStr;
}

export function diffProps(props,keyArr) {
    let new_props = {};
    Object.keys(props).forEach(key => {
        if (keyArr.indexOf(key) === -1){
            new_props[key] = props[key];
        }
    });
    return new_props;
}
